<template>
  <div class="user-search">
    <el-form label-width="80px" size="large" :model="searchForm" ref="formRef">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="用户名" prop="name">
            <el-input placeholder="请输入" v-model="searchForm.name">
            </el-input> </el-form-item
        ></el-col>
        <el-col :span="8">
          <el-form-item label="真实姓名" prop="realname">
            <el-input placeholder="请输入" v-model="searchForm.realname">
            </el-input> </el-form-item></el-col
        ><el-col :span="8">
          <el-form-item label="电话号码" prop="cellphone">
            <el-input placeholder="请输入" v-model="searchForm.cellphone">
            </el-input> </el-form-item
        ></el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="enable">
            <el-select placeholder="请选择" v-model="searchForm.enable">
              <el-option label="启用" :value="0" />
              <el-option label="禁用" :value="1" /> </el-select></el-form-item
        ></el-col>
        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <el-date-picker
              v-model="searchForm.createAt"
              type="daterange"
              range-separator="-"
              start-placeholder="Start date"
              end-placeholder="End date"
            /> </el-form-item
        ></el-col>
      </el-row>
    </el-form>
    <div class="btn">
      <el-button
        type="primary"
        icon="Refresh"
        size="large"
        @click="handleResetClick"
        >重置</el-button
      >
      <el-button
        type="primary"
        icon="Search"
        size="large"
        @click="handleQueryClick"
        >搜索</el-button
      >
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import type { ElForm } from 'element-plus'
const searchForm = ref({
  name: '',
  realname: '',
  cellphone: '',
  enable: '',
  createAt: ''
})
const emit = defineEmits(['resetClick', 'queryClick'])
const formRef = ref<InstanceType<typeof ElForm>>()
function handleResetClick() {
  formRef.value?.resetFields() //重置表单数据
  //将事件传出去，content内部重新发送请求
  emit('resetClick')
}
function handleQueryClick() {
  emit('queryClick', searchForm.value)
}
</script>

<style lang="less" scoped>
.user-search {
  background-color: #fff;
  padding: 20px;
  .el-form-item {
    margin-bottom: 0;
    padding: 20px 30px;
  }
  .btn {
    text-align: right;
    padding: 0 50px 10px 0;
  }
}
</style>
